package com.kuaidi100.sdk.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.apache.commons.lang3.builder.ToStringBuilder;
import org.apache.commons.lang3.builder.ToStringStyle;

import java.util.List;
/**
 * 快递查询结果类
 */
public class ExpressTracking {
    private String message;
    private String nu;
    /**
     * 是否签收标记，0未签收，1已签收
     */
    private String ischeck;
    private String com;
    private String status;
    /**
     * 最新查询结果，数组，包含多项，全量，倒序
     */
    private List<TrackingData> data;
    /**
     * 快递单当前状态，默认为0在途，1揽收，2疑难，3签收，4退签，5派件，8清关，14拒签等10个基础物流状态，如需要返回高级物流状态，请参考 resultv2 传值
     */
    private String state;
    /**
     * 快递单明细状态标记，暂未实现，请忽略
     */
    private String condition;
    private RouteInfo routeInfo;
    private boolean isLoop;

    @Override
    public String toString() {
        try {
            ObjectMapper objectMapper = new ObjectMapper();
            return objectMapper.writeValueAsString(this);
        } catch (Exception e) {
            return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                    .append("message", message)
                    .append("nu", nu)
                    .append("ischeck", ischeck)
                    .append("com", com)
                    .append("status", status)
                    .append("data", data)
                    .append("state", state)
                    .append("condition", condition)
                    .append("routeInfo", routeInfo)
                    .append("isLoop", isLoop)
                    .toString();
        }
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getNu() {
        return nu;
    }

    public void setNu(String nu) {
        this.nu = nu;
    }

    public String getIscheck() {
        return ischeck;
    }

    public void setIscheck(String ischeck) {
        this.ischeck = ischeck;
    }

    public String getCom() {
        return com;
    }

    public void setCom(String com) {
        this.com = com;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public List<TrackingData> getData() {
        return data;
    }

    public void setData(List<TrackingData> data) {
        this.data = data;
    }

    public String getState() {
        return state;
    }

    public void setState(String state) {
        this.state = state;
    }

    public String getCondition() {
        return condition;
    }

    public void setCondition(String condition) {
        this.condition = condition;
    }

    public RouteInfo getRouteInfo() {
        return routeInfo;
    }

    public void setRouteInfo(RouteInfo routeInfo) {
        this.routeInfo = routeInfo;
    }

    public boolean isLoop() {
        return isLoop;
    }

    public void setLoop(boolean loop) {
        isLoop = loop;
    }

    // 物流轨迹数据类
    public static class TrackingData {
        /**
         * 时间，原始格式
         */
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
        private String time;
        /**
         * 内容
         */
        private String context;
        /**
         * 格式化后时间
         */
        @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
        private String ftime;
        /**
         * 本数据元对应的行政区域的编码，实时查询接口中提交resultv2=1或者resultv2=4标记后才会出现
         */
        private String areaCode;
        /**
         * 本数据元对应的区域名称，实时查询接口中提交resultv2=1或者resultv2=4标记后才会出现
         */
        private String areaName;
        /**
         * 本数据元对应的高级物流状态值，实时查询接口中提交resultv2=4标记后才会出现
         */
        private String status;
        /**
         * 本数据元对应的快件当前地点，实时查询接口中提交resultv2=4标记后才会出现
         */
        private String location;
        /**
         * 本数据元对应的行政区域经纬度，提交resultv2=4标记后才会出现
         */
        private String areaCenter;
        /**
         * 本数据元对应的行政区域拼音，提交resultv2=4标记后才会出现
         */
        private String areaPinYin;
        /**
         * 本数据元对应的快件当前地点，实时查询接口中提交resultv2=4标记后才会出现
         */
        private String statusCode;

        @Override
        public String toString() {
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                return objectMapper.writeValueAsString(this);
            } catch (Exception e) {
                return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                        .append("time", time)
                        .append("context", context)
                        .append("ftime", ftime)
                        .append("areaCode", areaCode)
                        .append("areaName", areaName)
                        .append("status", status)
                        .append("location", location)
                        .append("areaCenter", areaCenter)
                        .append("areaPinYin", areaPinYin)
                        .append("statusCode", statusCode)
                        .toString();
            }
        }

        public String getTime() {
            return time;
        }

        public void setTime(String time) {
            this.time = time;
        }

        public String getContext() {
            return context;
        }

        public void setContext(String context) {
            this.context = context;
        }

        public String getFtime() {
            return ftime;
        }

        public void setFtime(String ftime) {
            this.ftime = ftime;
        }

        public String getAreaCode() {
            return areaCode;
        }

        public void setAreaCode(String areaCode) {
            this.areaCode = areaCode;
        }

        public String getAreaName() {
            return areaName;
        }

        public void setAreaName(String areaName) {
            this.areaName = areaName;
        }

        public String getStatus() {
            return status;
        }

        public void setStatus(String status) {
            this.status = status;
        }

        public String getLocation() {
            return location;
        }

        public void setLocation(String location) {
            this.location = location;
        }

        public String getAreaCenter() {
            return areaCenter;
        }

        public void setAreaCenter(String areaCenter) {
            this.areaCenter = areaCenter;
        }

        public String getAreaPinYin() {
            return areaPinYin;
        }

        public void setAreaPinYin(String areaPinYin) {
            this.areaPinYin = areaPinYin;
        }

        public String getStatusCode() {
            return statusCode;
        }

        public void setStatusCode(String statusCode) {
            this.statusCode = statusCode;
        }
    }

    // 路线信息类
    public static class RouteInfo {
        /**
         * 出发地行政区信息
         */
        private Area from;
        /**
         * 当前地行政区信息
         */
        private Area cur;
        /**
         * 目的地行政区信息
         */
        private Area to;

        @Override
        public String toString() {
            try {
                ObjectMapper objectMapper = new ObjectMapper();
                return objectMapper.writeValueAsString(this);
            } catch (Exception e) {
                return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                        .append("from", from)
                        .append("cur", cur)
                        .append("to", to)
                        .toString();
            }
        }

        public Area getFrom() {
            return from;
        }

        public void setFrom(Area from) {
            this.from = from;
        }

        public Area getCur() {
            return cur;
        }

        public void setCur(Area cur) {
            this.cur = cur;
        }

        public Area getTo() {
            return to;
        }

        public void setTo(Area to) {
            this.to = to;
        }

        public static class Area {
            /**
             * 政区信息编码
             */
            private String number;
            /**
             * 政区信息名称
             */
            private String name;

            @Override
            public String toString() {
                try {
                    ObjectMapper objectMapper = new ObjectMapper();
                    return objectMapper.writeValueAsString(this);
                } catch (Exception e) {
                    return new ToStringBuilder(this, ToStringStyle.MULTI_LINE_STYLE)
                            .append("number", number)
                            .append("name", name)
                            .toString();
                }
            }

            public String getNumber() {
                return number;
            }

            public void setNumber(String number) {
                this.number = number;
            }

            public String getName() {
                return name;
            }

            public void setName(String name) {
                this.name = name;
            }
        }
    }
}